package com.chinasofti.udp;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;

public class ServerDemo {
    public static void main(String[] args) throws IOException {
        //创建发送端的Socket对象
        MulticastSocket ms = new MulticastSocket(10000);
        //创建接收数据的packet
        DatagramPacket dp = new DatagramPacket(new byte[1024],1024 );
        //绑定主播网址
        ms.joinGroup(InetAddress.getByName("224.0.1.0"));
        //接收数据
        ms.receive(dp);
        byte[] data=dp.getData();
        int length = dp.getLength();
        System.out.println(new String(data,0,length));
        ms.close();
    }
}
